package com.yjhb.android.sbz.adapter;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.yjhb.android.sbz.R;
import com.yjhb.android.sbz.entity.LevelUser;
import com.jojo.android.zxlib.base.BaseRecyclerAdapter;
import com.jojo.android.zxlib.tool.ZxSpanTool;
import com.jojo.android.zxlib.tool.ZxTimeTool;
import com.jojo.android.zxlib.view.CircleImageView;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 创建者 zx
 * 创建时间 2020/12/30 15:19
 */
public class LevelFiendAdapter extends BaseRecyclerAdapter<LevelFiendAdapter.LevelHolder, LevelUser> {
    private final String TAG = "LevelFiendAdapter";


    public LevelFiendAdapter(Context context) {
        super(context);
    }

    @Override
    protected LevelHolder getHolder(View v) {
        return new LevelHolder(v);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.item_level_friend;
    }

    @Override
    public void onBindViewHolder(@NonNull LevelHolder holder, int position) {

        holder.dateTv.setText("注册时间：" + ZxTimeTool.getTimeStr(entity.getFriendCreateTime()));
        Glide.with(context).load(entity.getFriendAvatar()).apply(new RequestOptions().placeholder(R.mipmap.test_head)).into(holder.headIv);
        holder.moneyTv.setText("奖" + entity.getTotalShare() + "元");
        String name = entity.getFriendNickName();
        if (name.length() > 0) {
            if (name.length() > 2) {
                holder.userTv.setText(name.substring(0, 2) + "**");
            } else {
                holder.userTv.setText(name.substring(0, 1) + "**");
            }
        }
        holder.userIdTv.setText("ID:" + entity.getFriendId());
        CharSequence charSequence = "佣金总收入：" + entity.getTotalShare() + "元";
        holder.total_money_tv.setText(ZxSpanTool.ColorSpan(charSequence, 6,
                charSequence.length(), context.getResources().getColor(R.color.red_4040)));
        if (entity.getFriendType() == 1) {
            holder.label_tv.setText("徒弟");
        } else {
            holder.label_tv.setText("徒孙");
        }
        if (entity.getGetMoneyNum() > 0) {
            holder.status_tv.setText("已提现");
        } else {
            holder.status_tv.setText("暂未提现");
        }
    }


    class LevelHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.head_iv)
        CircleImageView headIv;
        @BindView(R.id.user_tv)
        TextView userTv;
        @BindView(R.id.userId_tv)
        TextView userIdTv;
        @BindView(R.id.date_tv)
        TextView dateTv;
        @BindView(R.id.money_tv)
        TextView moneyTv;
        @BindView(R.id.label_tv)
        TextView label_tv;
        @BindView(R.id.total_money_tv)
        TextView total_money_tv;
        @BindView(R.id.status_tv)
        TextView status_tv;

        public LevelHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}
